﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:COL_LOANEXT
	/// </summary>
	public partial class COL_LOANEXT : BaseDAL<GSLMS.Entity.TB_COL_LOANEXT>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public COL_LOANEXT()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_COL_LOANEXT model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_STARTPHASE", model.STARTPHASE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_RATE", model.RATE),
								new OracleParameter("P_MANAGEFEERATE", model.MANAGEFEERATE),
								new OracleParameter("P_GENERALRATE", model.GENERALRATE),
								new OracleParameter("P_DELAYRATE", model.DELAYRATE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_APPLYBY", model.APPLYBY),
								new OracleParameter("P_APPLYDATE", model.APPLYDATE),
								new OracleParameter("P_TOUSER", model.TOUSER),
								new OracleParameter("P_REVIEW", model.REVIEW),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_STATUS", model.STATUS)};
  
			for (int i = 0; i < 18; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_loanext_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_COL_LOANEXT model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_STARTPHASE", model.STARTPHASE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_RATE", model.RATE),
								new OracleParameter("P_MANAGEFEERATE", model.MANAGEFEERATE),
								new OracleParameter("P_GENERALRATE", model.GENERALRATE),
								new OracleParameter("P_DELAYRATE", model.DELAYRATE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_APPLYBY", model.APPLYBY),
								new OracleParameter("P_APPLYDATE", model.APPLYDATE),
								new OracleParameter("P_TOUSER", model.TOUSER),
								new OracleParameter("P_REVIEW", model.REVIEW),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_STATUS", model.STATUS)};
  
			for (int i = 0; i < 18; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_loanext_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_loanext_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_COL_LOANEXT DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_COL_LOANEXT model = new GSLMS.Entity.TB_COL_LOANEXT();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["LOANID"]!=null && dr["LOANID"].ToString()!="")
				{
					model.LOANID=OracleHelper.ToLong(dr["LOANID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["STARTPHASE"]!=null && dr["STARTPHASE"].ToString()!="")
				{
                    model.STARTPHASE = OracleHelper.ToInt(dr["STARTPHASE"].ToString());
				}
				if(dr["ENDDATE"]!=null && dr["ENDDATE"].ToString()!="")
				{
					model.ENDDATE=DateTime.Parse(dr["ENDDATE"].ToString());
				}
				if(dr["AMT"]!=null && dr["AMT"].ToString()!="")
				{
					model.AMT=OracleHelper.ToDecimal(dr["AMT"].ToString());
				}
				if(dr["RATE"]!=null && dr["RATE"].ToString()!="")
				{
					model.RATE=OracleHelper.ToDecimal(dr["RATE"].ToString());
				}
				if(dr["MANAGEFEERATE"]!=null && dr["MANAGEFEERATE"].ToString()!="")
				{
					model.MANAGEFEERATE=OracleHelper.ToDecimal(dr["MANAGEFEERATE"].ToString());
				}
				if(dr["GENERALRATE"]!=null && dr["GENERALRATE"].ToString()!="")
				{
					model.GENERALRATE=OracleHelper.ToDecimal(dr["GENERALRATE"].ToString());
				}
				if(dr["DELAYRATE"]!=null && dr["DELAYRATE"].ToString()!="")
				{
					model.DELAYRATE=OracleHelper.ToDecimal(dr["DELAYRATE"].ToString());
				}
				if(dr["LOANPHASETYPE"]!=null && dr["LOANPHASETYPE"].ToString()!="")
				{
                    model.LOANPHASETYPE = OracleHelper.ToInt(dr["LOANPHASETYPE"].ToString());
				}
				if(dr["APPLYBY"]!=null && dr["APPLYBY"].ToString()!="")
				{
					model.APPLYBY=dr["APPLYBY"].ToString();
				}
				if(dr["APPLYDATE"]!=null && dr["APPLYDATE"].ToString()!="")
				{
					model.APPLYDATE=DateTime.Parse(dr["APPLYDATE"].ToString());
				}
				if(dr["TOUSER"]!=null && dr["TOUSER"].ToString()!="")
				{
					model.TOUSER=dr["TOUSER"].ToString();
				}
				if(dr["REVIEW"]!=null && dr["REVIEW"].ToString()!="")
				{
					model.REVIEW=dr["REVIEW"].ToString();
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_COL_LOANEXT GetByID(long ID)
		{
			GSLMS.Entity.TB_COL_LOANEXT sModel = new GSLMS.Entity.TB_COL_LOANEXT();
			string sql = "";
			sql = "select * from TB_COL_LOANEXT where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_COL_LOANEXT> GetList(GSLMS.Entity.TB_COL_LOANEXT searchParam)
		{
			var list=new List<GSLMS.Entity.TB_COL_LOANEXT>();
			DataTable dt = null;
			string tblName = "TB_COL_LOANEXT";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_COL_LOANEXT model = new GSLMS.Entity.TB_COL_LOANEXT();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

